<?php
/**
 * User: aka
 * Time: 0:38
 */

namespace app\write\controller;

use app\validate\messageBoard\SendMessage;
use think\facade\Session;
use think\Request;

class MessageBoard
{
    private $userId;

    public function __construct()
    {
        $this->userId = Session::get('user_info.id');
    }

    public function __destruct()
    {
        unset(
            $this->userId
        );
    }

    public function sendMessage(Request $request)
    {
        $validate = new SendMessage();
        if (!$validate->check($request->param())) {
            return json($validate->getError());
        }else{
            \app\tenno\model\Message::create([
                'content' => $request->param('content'),
                'uid' => $this->userId
            ]);
            return json([
                'state' => 200,
                'game_id' => Session::get('user_info.game_id'),
                'now_time' => get_time()
            ]);
        }
    }
}